<!DOCTYPE HTML>
<html>
<head>
    <title>部落管理</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 98%">
<div style="width:100%;height:87%;">
    <div showCollapseButton="true" style="width: 100%;height: 100%">
        <div id="outImg">
            <img id="imgId" src="" alt="" onclick="smallImg()">
        </div>
        <div style="padding: 5px">
            <span>用户昵称：</span><input class="mini-textbox" type="text" id="nickName"/>
            <span>用户id：</span><input class="mini-textbox" type="text" id="objectId"/>
            <span>用户电话：</span><input class="mini-textbox" type="text" id="mobilePhoneNumber"/>
            <span>部落id：</span><input class="mini-textbox" type="text" id="uid"/>
            <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
        </div>
        <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 33%;"
             url="/getdata/usersInformation" idField="id" allowResize="true" onselectionchanged="onSelectionChanged"
             sizeList="[20,30,50,100]" pageSize="20"
        >
            <!--allowCellEdit="true" allowCellSelect="true" multiSelect="true"-->
            <div property="columns">
                <div field="objectId" width="80" headerAlign="center" allowSort="true" >objectId</div>
                <div field="nickName" width="80" headerAlign="center" allowSort="true" >用户昵称</div>
                <div field="gender"  width="70" align="center" headerAlign="center" allowSort="true" >用户iocn</div>
                <div field="live_authority"  align="center" width="60" headerAlign="center" allowSort="true">直播权限</div>
                <div field="sex" width="40"  align="center" headerAlign="center" allowSort="true">性别</div>
                <div field="uid" align="center" width="60" headerAlign="center" allowSort="true">部落id</div>
                <div field="signature" align="left" width="100" headerAlign="center" allowSort="true">个性签名</div>
                <div field="mobilePhoneNumber" align="center" headerAlign="center" width="70" allowSort="true" >电话号码</div>
                <div field="phoneRegVerify" align="center" headerAlign="center" width="70" allowSort="true" >手机验证</div>
                <div field="status" align="center" headerAlign="center" width="70" allowSort="true"  >账号状态</div>
                <div field="userType" align="center" headerAlign="center" width="70" allowSort="true" >账号类型</div>
                <div field="address" align="center" headerAlign="center" width="70" allowSort="true" >账号地理位置</div>
            </div>
        </div>
       <h2>地址列表</h2>
        <div style="width:99%;">
            <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <a class="mini-button" iconCls="icon-add" onclick="tribeMemberAdd()">增加</a>
                            <a class="mini-button" iconCls="icon-edit" onclick="tribeMemberEdit()">编辑</a>
                            <!--<a class="mini-button" iconCls="icon-remove" onclick="tribeMemberRemove()">删除</a>-->
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="datagrid2" class="mini-datagrid" style="width:99%;height:60%;" url="/getdata/userAddress"
             sizeList="[20,30,50,100]" pageSize="20" onselectionchanged="onSelectedChanged" allowResize="true">
            <!--idField="id" allowResize="true" sizeList="[20,30,50,100]" pageSize="20"-->
            <div property="columns">
                <div type="checkcolumn" width="15" ></div>
                <div field="objectId" width="60"  align="center" headerAlign="center">objectId</div>
                <div field="address" width="150"  align="left" headerAlign="center">收货地址</div>
                <div field="isDefault"  width="30" align="center" headerAlign="center"  >是否默认</div>
                <div field="name"  width="30" align="center" headerAlign="center"  >收货人</div>
                <div field="tel"  width="50" align="center" headerAlign="center"  >手机号</div>
                <div field="province"  width="50" align="center" headerAlign="center"  >省</div>
                <div field="city"  width="50" align="center" headerAlign="center"  >城市</div>
                <div field="oldUserOId"  width="50" align="center" headerAlign="center"  >oldUserOId</div>
                <div field="createdAt" width="40" align="center" headerAlign="center">创建日期</div>
                <div field="updatedAt" width="40" align="center" headerAlign="center">更新日期</div>
            </div>
        </div>
    </div>

</div>
</body>
<script type="text/javascript">
    var flag = 1;
    var groupType;
    var tribeName;
    var tribeCategory = '推荐';
    mini.parse();
    var grid = mini.get("datagrid1");
    var grid2 = mini.get("datagrid2");
    grid.load();
    grid.on("drawcell", function (e) {
        var value = e.value;
        var column = e.column;
        if (column.field == "gender") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }

        if (column.field == "phoneRegVerify") {
            parseInt(value)
            if(value == 1) {
                e.cellHtml = '<text>通过验证</text>';
            }else{
                e.cellHtml = '<text>未通过验证</text>';
            }
        }

        if (column.field == "live_authority") {
            parseInt(value)
            if(value == 1||value == true) {
                e.cellHtml = '<text>可以直播</text>';
            }else {
                e.cellHtml = '<text>不能直播</text>';
            }
        }
        if (column.field == "status") {
            if(value == 0) {
                e.cellHtml = '<text>不允许登陆</text>';
            }else  {
                e.cellHtml = '<text>可以登陆</text>';
            }
        }

    });

    function search() {
        var nickName = mini.get("nickName").getValue();
        var objectId = mini.get("objectId").getValue();
        var mobilePhoneNumber = mini.get("mobilePhoneNumber").getValue();
        var uid = mini.get("uid").getValue();
        grid.load({
            nickName: nickName,
            objectId:objectId,
            mobilePhoneNumber:mobilePhoneNumber,
            uid:uid,
        });
    }
    function searchStatus() {
        var status = mini.get("status").getValue();
        grid.load({
            status: status
        });
    }
    $("#nickName,#objectId,#mobilePhoneNumber,#uid").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });




    function bigImg() {
        var row = grid.getSelected();
        if (row) {
            var path = row.gender;
            $("#imgId").attr('src', path);
            $("#outImg").css('display','block');

        }
    }

    function smallImg() {
        $("#outImg").css('display','none');
    }



    function onSelectionChanged(e) {
        var tribeGrid = e.sender;
        var record = tribeGrid.getSelected();
        if (record) {
            groupType = record.objectId;
            grid2.load({userOId:record.objectId});
        }
    }

    grid2.on("drawcell", function (e) {
        var value = e.value;
        var column = e.column;
        if (column.field =="isDefault") {
            if (value==1) {
                e.cellHtml = '<text>是<text>';
            } else {
                e.cellHtml = '<text>否<text>';
            }
        }
    });
    function userBigImg() {
        var row = grid2.getSelected();
        if (row) {
            var path = row.qrCode;
            $("#imgId").attr('src', path);
            $("#outImg").css('display','block');

        }
    };
    function userBigImgCode() {
        var row = grid2.getSelected();
        if (row) {
            if(flag==1) {
                var path = row.userQrCode;
                $("#imgId").attr('src', path);
                $("#outImg").css('display','block');
            }
        }
    };


    function onSelectedChanged(e) {
        var tribeMemberGrid = e.sender;
        var record = tribeMemberGrid.getSelected();
        if (record) {
            userOId = record.userOId;
//      grid2.load({tribeOId:record.objectId});
        }
    };
    function tribeMemberAdd() {
        if (groupType == "" || groupType == undefined || groupType == null){
            alert('请先选择一个用户');
            return;
        };
        mini.open({
            url: "/getdata/userAddress/add?userOId=" + groupType,
            title: "添加收货地址", width: 600, height: 400,
            onload: function () {
                grid2.reload();
            },
            ondestroy: function (action) {
//        tribeOId = '';
//        grid.reload();
                grid2.reload();
            }
        });
    };
    function tribeMemberEdit() {
        var row2 = grid2.getSelected();
        if(row2){
            mini.open({
                url: "/getdata/userAddress/edit?objectId="+row2.objectId,
                title: "编辑群信息", width: 600, height: 400,
                onload: function () {
                },
                ondestroy: function (action) {
                    grid2.reload();
                }
            });
        } else {
            alert("请选中一个地址!");
            return;
        };

    };

    function tribeMemberRemove() {
        var row2 = grid2.getSelected();
        if (row2) {
            $.ajax({
                url: "/getdata/wxGroup/remove",
                type: 'post',
                data: {
                    objectId:row2.objectId
                },
                success: function (result) {
                    if (result==1){
                        alert('删除成功！');
                    } else {
                        alert('删除失败，请重试！');
                        return;
                    }
                    grid2.reload();
                },
                error: function (error) {
                    console.log(error)
                }
            });
        } else {
            alert("请选中一条记录");
        }
    }
</script>
</html>
